package com.zzzzzz.oms.wave;

import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.validation.ConstraintViolationException;
import javax.validation.Validator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.zzzzzz.core.datagrid.BaseData;
import com.zzzzzz.plugins.shiro.I;
import com.zzzzzz.utils.BeanValidators;
import com.zzzzzz.utils.DateTimeUtils;

@Service
public class WaveService {
	
	@Resource
	public WaveDao waveDao;
	
	@Resource
	public Validator validator;
	
	@Transactional
	public int save(Wave wave, I i) {
		wave.setUpdDt(new Date());
		wave.setUpdBy(i.getId());
		if (wave.getId() == null) {
			wave.setPlatformId(i.getPlatformId());
			wave.setAddDt(new Date());
			wave.setAddBy(i.getId());
			waveDao.add(wave);
		} else {
			waveDao.updById(wave);
		}

		return 1;
	}
	
	// 通过cd找id,主要给分段订单增加波次属性值。
	public Long getWaveByCd(String cd,Long platformId) {
		Map<String, List<Wave>> allWaveMap=waveDao.getAllWaveMap();
		List<Wave> waveList=allWaveMap.get(cd);
		if(waveList!=null){
			for(Wave wave:waveList){
				if(wave.getPlatformId().equals(platformId)){
					return wave.getId();
				}
			}
		}
		return null;
	}
	
	private static final Logger logger = LoggerFactory.getLogger(Wave.class);
}
